﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClientDBAgent;


namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ClientDBAgent agent = new ClientDBAgent();
           
           SqlDataItem sqlItem = new SqlDataItem();
           sqlItem.CommandText = "select * from Products where productid=@productid select * from Orders";
           //sqlItem.CommandType = CommandType.Text;
           sqlItem.AppendParameter("@productid", "2");
           DataSet ds = agent.ExecuteQuery(sqlItem);
           dataGridView1.DataSource = ds.Tables[1];
            
        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                SqlDataItem sqlItem = new SqlDataItem();
                sqlItem.CommandText = "update  Orders set shipname=@shipname where orderid=@orderid";
                //sqlItem.CommandType =CommandType.Text;
                sqlItem.AppendParameter("@orderid", "10248");
                sqlItem.AppendParameter("@shipname", "冯艳丽009");

                SqlDataItem sqlItem1 = new SqlDataItem();
                sqlItem1.CommandText = "update  [Order Details] set quantity=@quantity where orderid=@orderid";
                //sqlItem1.CommandType = CommandType.Text;
                sqlItem1.AppendParameter("@orderid", "10248");
                sqlItem1.AppendParameter("@quantity", "25");

                SqlDataItemArray sqlitemAry = new SqlDataItemArray();
                sqlitemAry.AppendSqlItem(sqlItem);
                sqlitemAry.AppendSqlItem(sqlItem1);
                ClientDBAgent agent = new ClientDBAgent();
                bool i = agent.ExecuteNonQueryArray(sqlitemAry);
                textBox1.Text = i.ToString();
            }
            catch (Exception ex)
            {
                textBox1.Text = ex.Message.ToString();
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ClientDBAgent agent = new ClientDBAgent();
            SqlDataItem sqlItem = new SqlDataItem();
            sqlItem.CommandText = "select * from Products where productid=@productid";
             sqlItem.CommandType = CommandType.Text.ToString();
            sqlItem.AppendParameter("@productid", "2");
            bool b = agent.RecordExists(sqlItem);
            textBox1.Text = b.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ClientDBAgent agent = new ClientDBAgent();

            SqlDataItem sqlItem = new SqlDataItem();
            sqlItem.CommandText = "select * from [work] where caption=@caption";
            sqlItem.CommandType = CommandType.Text.ToString();
            sqlItem.AppendParameter("@caption", "产品拍照");
            DataSet ds = agent.ExecuteQuery(sqlItem);
            dataGridView1.DataSource = ds.Tables[0];
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            ConfigurationSettings.AppSettings["DataClientType"] = "ACCESS";
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            ConfigurationSettings.AppSettings["DataClientType"] = "SQLSERVER";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ClientDBAgent agent = new ClientDBAgent();
            agent.GetBlankTable("HF_workflow");
        }
    }
}
